<?php
include("admin_check.php");
include_once("../function.php");
include_once("../class/member_class.php");
include_once("../class/ulevel_class.php");


set_time_limit(0);
ignore_user_abort(true);
session_start();
header("Content-Type: text/html;charset=utf-8");
checkqx(1,1);?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link href="css/style.css" rel="stylesheet" type="text/css">
    <script src="../js/calendar.js"></script>
    <link href="../layui-master/dist/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../layui-master/dist/layui.js"></script>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#TimeStart' //指定元素
            });
            laydate.render({
                elem: '#TimeEnd' //指定元素
            });
        });
    </script>
    <?php
    #搜索会员
    if ($_POST['Search']){
        $SearchContent=$_POST['SearchContent'];
        $TimeStart=$_POST['TimeStart'];
        $TimeEnd=$_POST['TimeEnd'];
        if ($TimeStart!=NULL){
            if ($TimeEnd==NULL){
                $TimeEnd=now();
            }
            $_SESSION['SearchTime']="and rdt>='".$TimeStart."' and rdt<='".$TimeEnd."'";
        }else{
            $_SESSION['SearchTime']=NULL;
        }
        if ($SearchContent!=NULL){
            $SearchType=$_POST['SearchType'];
            if ($SearchType==1){
                #搜索会员编号
                $_SESSION['Search']="and nickname='".$SearchContent."'";
            }elseif($SearchType==2){
                #搜索推荐人
                $_SESSION['Search']="and rname='".$SearchContent."'";
            }elseif($SearchType==3){
                #搜索报单中心
                $_SESSION['Search']="and bdname='".$SearchContent."'";
            }
        }else{
            $_SESSION['Search']=NULL;
        }
    }else{
        if ($_GET['page']==NULL){
            $_SESSION['Search']=NULL;
            $_SESSION['SearchTime']=NULL;
        }
    }

    #激活会员
    if ($_POST['button']){

        $id = $_GET['id'];

        $sql="select userid,username,nickname,lsk,xian,fatherid,ulevel from member where id={$id}";
        $rs=getOne($sql);
        $sql2="select ispay from member where id={$rs['fatherid']}";
        $rs2=getOne($sql2);

        $_member=new member_class();
        $bonus_cl=new bonus_class();
        $chenggong=0;
        $shibai=0;
        $_member->jihuomember($id,1);
        //mysql_query("call shourulevel()");

        echo "<script language=javascript>alert('会员激活完成');window.location.href='?'</script>";



    }

    #顶层会员
    if ($_POST['button2']){
        $cheuid_arr = $_GET['id'];
        $_member=new member_class();
        foreach ((array)$cheuid_arr as $id)
        {
            $_member->dingcengmember($id);
        }
        echo "<script language=javascript>alert('会员已设置为团队领导.');window.location.href='?'</script>";
    }

    #回填会员
    if ($_POST['button3']){
        $id = $_GET['id'];
        $_member=new member_class();
        $_member->huitiandanmember($id);
        echo "<script language=javascript>alert('回填会员设置完成.');window.location.href='?'</script>";
    }

    #删除会员
    if ($_POST['button4']){
        $id = $_GET['id'];
        $_member=new member_class();
        if ($_member->checkfman($id)){
            edit_delete_cl('member',$id);
        }else{
            $us=$_member->getMemberbyID($id);
            echo "<script language=javascript>alert('会员".$us['nickname']."下方已经安置了会员,删除失败.');window.location.href='?'</script>";
        }
        echo "<script language=javascript>alert('删除会员完成.');window.location.href='?'</script>";
    }

    if($_POST['tijiao'])
    {
//    if($_POST['nickname'] && $_POST['money'])
//    {
//        echo "<script language=javascript>alert('发放成功');window.location.href='?'</script>";
//    }
//    else{
        echo "<script language=javascript>alert('发放成功');window.location.href='?'</script>";
//    }

    }
    ?>


    <title>激活会员</title>
    <SCRIPT LANGUAGE=javascript>
        <!--
        function SelectAll() {
            for (var i=0;i<document.form1.UID.length;i++) {
                var e=document.form1.UID[i];
                e.checked=!e.checked;
            }
        }
        -->
    </script>
</head>
<body>
<form name="form1" method="post" action="?">
    <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="layui-table" lay-skin="line">
        <tr>
            <td height="5" colspan="10" align="left">
                <select name="SearchType" id="SearchType">
                    <option value="1">会员编号</option>
                    <option value="2">推荐人</option>
                </select>
                <input type="text" name="SearchContent" id="SearchContent">
                <input type="submit" name="Search" id="Search" class="layui-btn layui-btn-small" value="搜索"></td>
        </tr>
        <tr>
            <td height="20" colspan="10" align="left">搜索时间范围：
                <input type="text" name="TimeStart" id="TimeStart" style="width:100px" >
                至
                <input type="text" name="TimeEnd" id="TimeEnd" style="width:100px" ></td>
        </tr>
</form>
<tr>
    <td height="20" colspan="10" align="center">会员激活</td>
</tr>
<tr>
    <td height="50" colspan="10" align="center"></td>

</tr>
<tr style="display:none">
    <td height="20" colspan="10" align="center"><font color=red>说明:1、在后台激活会员的，该会员所属的服务中心或者县区店不会扣除激活电子币，同样报单服务费或者店补也拿不到。2、空单会员不算业绩，但是空单伞下有实单业绩，空单可以拿到奖金。(以上操作仅限后台操作，会员区专卖店或者服务中心激活不存在这种情况)</font></td>
</tr>
<tr>
    <td height="21" align="center"><input type="checkbox" name="checkbox" value="checkbox" onClick="javascript:SelectAll()"></td>
    <td align="center">会员编号</td>
    <td align="center">会员姓名</td>
    <td style="display:none" align="center">投资金额</td>
    <td align="center">会员资格</td>
    <td align="center">推荐人姓名</td>
    <td align="center">注册人</td>
    <td align="center">报单时间</td>
    <td align="center">详细信息</td>
</tr>
</form>
<?php
$pagesize = 20; //设置每页记录数
$sql = "SELECT * FROM `member` WHERE ispay=0 and zb5=0";
if($query = mysql_query($sql)){
    $sum = mysql_num_rows($query); //计算总记录数
}else{
    $sum=0;
}
if($sum % $pagesize == 0) //计算总页数
    $total = (int)($sum/$pagesize);
else
    $total = (int)($sum/$pagesize) + 1;
if (isset($_GET['page'])) //获得页码
{
    $p = (int)$_GET['page'];
}
else
{
    $p = 1;
}
if ($p>$total){
    $p=$total;
}
$start = $pagesize * ($p - 1); //计算起始记录
$sql = "SELECT * FROM `member` WHERE ispay=0 and zb5=0";
if($query = mysql_query($sql)){
    while ($row=mysql_fetch_array($query)){
        $ul=ulevel($row['ulevel']);
        ?>
        <tr>

            <form name="form1" method="post" action="?id=<?=$row['id']?>">
                <td align="center"><input type="checkbox" name="checkbox" value="checkbox"></td>
                <td align="center"><?=$row['userid']?></td>
                <td align="center"><?=$row['username']?></td>
                <td style="display:none" align="center"><?=$row['lsk']?></td>
                <td align="center"><?=$ul['lvname']?></td>
                <td align="center"><?=$row['rname']?></td>
                <td align="center"><?=$row['bdname']?></td>
                <td align="center"><?=$row['rdt']?></td>
                <td style="display:none" align="center"><?=$row['userqq']?></td>
                <td align="center">
                    <input type="button"  class="layui-btn layui-btn-small layui-btn-normal" id="button" name="button1" value="查看" onClick="window.location.href='admin_UpdateProfile.php?ID=<?=$row['id']?>'" />
                    <input name="button" type="submit"  class="layui-btn layui-btn-small layui-btn-normal" id="button" value="激活会员" onClick="{if(confirm('您确定要激活该会员吗?')){this.document.selform.submit();return true;}return false;}">
                    <input name="button4" type="submit"  class="layui-btn layui-btn-small layui-btn-normal" id="button4" value="删除会员" onClick="{if(confirm('您确定要删除该会员吗?')){this.document.selform.submit();return true;}return false;}">
      <!--              <input name="button3" type="submit" class="layui-btn layui-btn-small layui-btn-normal" id="button3" value="回填会员" onClick="{if(confirm('您确定要将该会员设置为回填会员吗?')){this.document.selform.submit();return true;}return false;}">
       -->         </td>
            </form>
        </tr>

    <?php
    }
}
?>
</table>
</form>
</body>
</html>